﻿Imports BUS

Public Class frmQuanLy

    Private frmcho As DevExpress.Utils.WaitDialogForm

    Private Function CheckExistFrom(ByVal name As String) As Boolean
        Dim check As Boolean = False
        For Each frm As Form In Me.MdiChildren
            If (frm.Name = name) Then
                check = True
                Exit For
            End If
        Next
        Return check
    End Function

    Private Sub ActiveChildForm(ByVal name As String)
        For Each frm As Form In Me.MdiChildren
            If (frm.Name = name) Then
                frm.Update()
                frm.Activate()
                Exit For
            End If
        Next
    End Sub

    Private Sub frmQuanLy_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ProcFuncBus.CreateConnectionStringFromXml(Application.StartupPath + "\InfoDataBaseServer.xml")
    End Sub

    Private Sub tsmihosonhanvien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmihosonhanvien.Click
        If (CheckExistFrom("frmNhanVien") = False) Then
            Dim frm As New frmNhanVien()
            frm.MdiParent = Me
            frm.WindowState = FormWindowState.Maximized
            frm.Show()
        Else
            ActiveChildForm("frmNhanVien")
        End If
        'Dim frm As New frmNhanVien()
        'frm.ShowDialog()

    End Sub

    Private Sub tsmidulieuquetthe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmidulieuquetthe.Click
        If (CheckExistFrom("frmDuLieuQuet") = False) Then
            Dim frm As New frmDuLieuQuet()
            frm.MdiParent = Me
            frm.WindowState = FormWindowState.Maximized
            frm.Show()
        Else
            ActiveChildForm("frmDuLieuQuet")
        End If
    End Sub

    Private Sub tsmichamcongtay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmichamcongtay.Click
        Dim frm As New frmChamCongTay
        frm.ShowDialog()
    End Sub

    Private Sub tsmicongnhanvien_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmicongnhanvien.Click
        If (CheckExistFrom("frmCongNhanVien") = False) Then
            Dim frm As New frmpCongNhanVien()
            frm.MdiParent = Me
            frm.WindowState = FormWindowState.Maximized
            frm.Show()
        Else
            ActiveChildForm("frmCongNhanVien")
        End If
    End Sub

    Private Sub tsminhanviencongty_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub tsmigiocongthang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub tsmidong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmidong.Click
        Application.Exit()
    End Sub

    Private Sub tsmibophan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmibophan.Click

        If (CheckExistFrom("frmBPhan") = False) Then
            Dim frm As New frmBPhan()
            frm.MdiParent = Me
            frm.WindowState = FormWindowState.Maximized
            frm.Show()
        Else
            ActiveChildForm("frmBPhan")
        End If

        'Dim frm As New frmBPhan()
        'frm.ShowDialog()

    End Sub

    Private Sub tsmichucvu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmichucvu.Click
        If (CheckExistFrom("frmChucVu") = False) Then
            Dim frm As New frmChucVu()
            frm.MdiParent = Me
            frm.WindowState = FormWindowState.Maximized
            frm.Show()
        Else
            ActiveChildForm("frmChucVu")
        End If
    End Sub

    Private Sub CácLoạiCaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CácLoạiCaToolStripMenuItem.Click
        'If (CheckExistFrom("frmCacLoaiCa") = False) Then
        '    Dim frm As New frmCacLoaiCa()
        '    frm.MdiParent = Me
        '    frm.WindowState = FormWindowState.Maximized
        '    frm.Show()
        'Else
        '    ActiveChildForm("frmCacLoaiCa")
        'End If

        Dim frm As New frmCacLoaiCa
        frm.ShowDialog()
    End Sub

    Private Sub tsmicauhinhca_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsmicauhinhca.Click
        If (CheckExistFrom("frmCauHinhCa") = False) Then
            Dim frm As New frmCauHinhCa()
            frm.MdiParent = Me
            frm.WindowState = FormWindowState.Maximized
            frm.Show()
        Else
            ActiveChildForm("frmCauHinhCa")
        End If
    End Sub

    Private Sub BộPhậnToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BộPhậnToolStripMenuItem.Click
        Dim frm As New frmChonNgay
        frm.ShowDialog()
    End Sub

    Private Sub NgàyVàoLàmToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim frm As New frmChonNgay
        frm.ShowDialog()
    End Sub

    Private Sub CôngThángToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CôngThángToolStripMenuItem.Click
        Dim frm As New frmTuyChon
        frm.ShowDialog()
    End Sub

    Private Sub TấtCảToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TấtCảToolStripMenuItem.Click
        frmcho = New DevExpress.Utils.WaitDialogForm("Vui lòng chờ", "Đang xử lý")
        Dim rpt As New rptDanhSachNhanVien
        rpt.xrlTieuDe.Text = "DANH SÁCH NHÂN VIÊN"
        rpt.DataSource = ProcFuncBus.ExecuteFuncSQL("exec sp_laydanhsachnhanvien -1, 1, '2013-1-1', '2013-1-1'")
        rpt.CreateDocument()
        rpt.ShowPreview()
        frmcho.Close()
    End Sub

    Private Sub frmQuanLy_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        Application.Exit()
    End Sub
End Class
